package com.youku.plugins.endcardV4New.view
{
   import flash.display.Sprite;
   import com.youku.plugins.PluginEventDispather;
   import com.youku.plugins.endcardV4New.model.data.PlayerSizeData;
   import com.youku.interfaces.IRelativeVideoList;
   import com.youku.plugins.endcardV4New.model.data.PlayerVideoData;
   import flash.display.DisplayObject;
   import com.youku.interfaces.IEndCardV4New;
   
   public class EndCard extends Sprite
   {
      
      public function EndCard() {
         super();
         this.init();
      }
      
      private var _viewArray:Array;
      
      private var _container:Sprite;
      
      private var _searchBarHeight:Number = 32;
      
      private var _screenNum:uint;
      
      private var _background:Background;
      
      private var _relative:Relative;
      
      private var _shareBackground:ShareBackground;
      
      private function init() : void {
         this._viewArray = [];
      }
      
      public function show(param1:Object = null, param2:PluginEventDispather = null, param3:PlayerSizeData = null) : void {
         this.hide();
         var _loc4_:IRelativeVideoList = param1.relativeVideoList as IRelativeVideoList;
         var _loc5_:PlayerVideoData = param1.playerVideoData as PlayerVideoData;
         this._background = new Background();
         this._background.init(_loc5_,null,param3);
         this.addChild(this._background as DisplayObject);
         this._viewArray.push(this._background);
         this._container = new Sprite();
         addChild(this._container);
         this._relative = new Relative();
         this._relative.init(param1,param2,param3);
         this._container.addChild(this._relative as DisplayObject);
         this._viewArray.push(this._relative);
         this._shareBackground = new ShareBackground();
         this._shareBackground.init(null,param2,param3);
         addChild(this._shareBackground as DisplayObject);
         this._viewArray.push(this._shareBackground);
         this.changeSize(param3);
      }
      
      public function changeSize(param1:PlayerSizeData = null) : void {
         if(this._viewArray.length == 0)
         {
            return;
         }
         this._background.x = 0;
         this._background.y = 0;
         this._background.changeSize(param1);
         this._relative.changeSize(param1);
         this._relative.scaleX = this._relative.scaleY = param1.scale;
         this._relative.x = int((param1.width - this._relative.width * this._relative.scaleX) / 2);
         if(param1.isFullScreen)
         {
            this._relative.y = int((param1.height - this._relative.height * this._relative.scaleY) / 2);
         }
         else if(param1.winType == "exterior")
         {
            this._relative.y = int((param1.height - param1.cHeight - this._searchBarHeight - this._relative.height * this._relative.scaleY) / 2) + this._searchBarHeight;
         }
         else
         {
            this._relative.y = int((param1.height - param1.cHeight - this._relative.height * this._relative.scaleY) / 2);
         }
         
         this._shareBackground.x = 0;
         this._shareBackground.y = 0;
         this._shareBackground.changeSize(param1);
      }
      
      public function hide() : void {
         var _loc1_:* = 0;
         var _loc2_:IEndCardV4New = null;
         if(this._viewArray.length > 0)
         {
            _loc1_ = 0;
            while(_loc1_ < this._viewArray.length)
            {
               _loc2_ = this._viewArray[_loc1_] as IEndCardV4New;
               _loc2_.uninstall();
               if(this._container.contains(_loc2_ as DisplayObject))
               {
                  this._container.removeChild(_loc2_ as DisplayObject);
               }
               if(this.contains(_loc2_ as DisplayObject))
               {
                  this.removeChild(_loc2_ as DisplayObject);
               }
               _loc2_ = null;
               _loc1_++;
            }
            this._viewArray = [];
         }
      }
   }
}
